<% 
    var headContent = {
%>

<style>
/*附件上传*/
  .am-progress-xs {
    height: .2rem;
    }
  .am-progress {
    margin-bottom: 0;
    }
 </style>
<%
};
%>
<%layout("/common/_layout.html",{head:headContent}){ %>
	<%#ajax userTable:{%>
    <div class="am-cf am-padding">
      <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">用户管理</strong> / <small>机构管理</small></div>
    </div>
    <form id="listForm" class="am-form" action="${base}/organization/list" method="post"> 
	<div class="am-g">
	    <div class="am-u-sm-12">
	      <table class="am-table am-table-bordered am-table-radius table-main">
	        <tbody>
	          <tr>
	            <th class="am-text-middle">所属企业</th>
	            <td>
	               <div class="am-u-sm-10">
	                  <select data-am-selected="{btnSize: 'sm'}">
	                    <option value="option1">大掌柜</option>
            </select>
        </div>
	            </td>
	            <th class="am-text-middle">机构类型</th>
	            <td>
	              <div class="am-u-sm-10">
	                <select id="orgtype" name="orgtype" data-am-selected="{btnSize: 'sm'}">
	                <option value="-1" 
	                <%if (isEmpty(orgtype)||orgtype=="-1"){%>
	                   selected = "selected"
	                <%}%>
	                  >所有</option>
	                  
	                <option value="1" 
	                <%if (!isEmpty(orgtype)&&orgtype=="1"){%>
	                   selected = "selected"
	                <%}%>
	                  >机构</option>
	                  
	                <option value="2" 
	                <%if (!isEmpty(orgtype)&&orgtype=="2"){%>
	                   selected = "selected"
	                <%}%>
	                  >商家</option>
	                </select>
	                <input id="search_orgtype"  type="hidden"  class="am-form-field am-input-sm" value=${orgtype!}>
    </div>
	            </td>
	          </tr>
      
	          <tr>
	            <th class="am-text-middle">渠道编码</th>
	            <td>
	              <div class="am-u-sm-10">
	                
	                <input id="NumCode" name="NumCode" type="text" class="am-form-field am-input-sm" value="${NumCode!}">
                    <input id="search_NumCode" type="hidden" class="am-input-sm"  value="${NumCode!}"/>
	                
	              </div>
	            </td>
	            <th class="am-text-middle">机构名称</th>
	            <td>
	              <div class="am-u-sm-10">
	                <input id="DisplayName" name="DisplayName" type="text"  class="am-form-field am-input-sm" value="${DisplayName!}">
                    <input id="search_DisplayName" type="hidden" class="am-input-sm"  value="${DisplayName!}"/>
    </div>
	            </td>
	          </tr>
	          <tr>
	              <td colspan="4">
	                <div align='right'>
	                  <button type="submit" class="am-btn am-btn-default am-btn-sm am-text-secondary">搜索</button>
    </div>
	              </td>
	          </tr>
	        </tbody>
	      </table>
  </div>
</div>
       </form> 
    <%if(so.hasPermission("ORGANIZATION_LOAD")) {%>
	<div class="am-g" id='div_load' >
	<div class="am-u-sm-12">
	   <div class="am-form-file am-text-xs">
                  <button type="button" class="am-btn am-btn-primary am-btn-sm">
                    <i class="am-icon-cloud-upload"></i> 导入机构数据
                  </button>
                  <input id="file_upload" type="file" name="file_upload">
       </div>
	    <div id="progress-area" class="am-margin-top-sm am-hide">
             <div id="progress-text" class="am-text-xs am-text-right"></div>
             <div id="progress" class="am-progress am-progress-xs">
                    <div class="am-progress-bar" style="width: 0%"></div>
             </div>
		</div>
		</div>
	</div>
	<%}%>
    <div class="am-g">
      <div class="am-u-sm-12">
        <div class="am-scrollable-horizontal">
          <table class="am-table am-table-striped am-table-hover table-main">
            <thead>
              <tr class="am-text-nowrap">
                <th class="table-check"><input id="cb_delete_all" type="checkbox"  /></th><th class="table-title">渠道编码</th><th class="table-title">机构名称</th><th class="table-title">机构类型</th><th class="table-title">上层机构</th><th class="table-title">主要业务</th><th class="table-title">网点类型名称</th><th class="table-title">APPID</th><th class="table-title">排序</th><th class="table-title">状态</th>
                 <%if(so.hasPermission("ORGANIZATION_EDIT")) {%>
                <th class="table-title">操作</th>
                <%}%>
              </tr>
          </thead>
           <tbody >
              <%for(list in pager.list){%>
                 <tr>
                  <td><input name="cb_delete" type="checkbox"  value="${list.id}"></td>              
                  <td>${list.NumCode}</td>           
                  <td>${list.DisplayName}</td>
                  <td>
                  	<%if (list.orgtype==1){%>
	                	企业
		            <%}else if(list.orgtype==2){%>
		                	商家
                	<%}else{%>
                                                                                    商家
		            <%}%>
                  </td>
                  <td>${list.parentname}</td>
                  <td>${list.Business}</td>
                  <td>${list.class_name}</td>
                  <td>${list.appid}</td>
                  <td>${list.DisplayOrder}</td>
                  <td>
                    <%if (list.enabled!=1){%>
	                	无效
		            <%}else{%>
		                	有效
		            <%}%>
            	  </td>
                  <%if(so.hasPermission("ORGANIZATION_EDIT")) {%>
                  <td>
                  <button onclick="location.href='${base!}/organization/edit?id=${list.id}&id=${list.id}'" type="button" class="am-btn am-btn-default am-btn-xs am-text-secondary" ><span class="am-icon-pencil-square-o"></span>编辑</button>
                  </td>
                   <%}%>
                </tr>
              <%}%> 
           </tbody>
        </table>
        </div>
         <div class="am-cf">
            <!-- 分页 -->
            <%if (pager.list.~size > 0){%>
                <div class="am-fr">
                <% include("/admin/organization_pager.tpl"){}%>	
                </div>
            <%}else{%>
                <div class="am-kai">
                  <h3>没有找到任何记录!</h3>
                </div>
            <%}%>
         </div>

        <%}%>
    </div>

    </div>
 <script src="${base}/template/jQuery-File-Upload/js/vendor/jquery.ui.widget.js"></script>
 <script src="${base}/template/jQuery-File-Upload/js/jquery.iframe-transport.js"></script>
 <script src="${base}/template/jQuery-File-Upload/js/jquery.fileupload.js"></script>
  <script type="text/javascript">
		$(function() {
            var index;
			/*附件上传：begin*/
            var jqXHR = $('#file_upload').fileupload({
              url: "${base}/organization/load/",
              dataType: 'json',
              start: function (e) {
                index = parent.layer.load(0, {
                      shade: [0.1,'#fff'] //0.1透明度的白色背景
                });
                $("#progress-area").removeClass("am-hide");
                $("#progress-text").removeClass("am-text-danger");
                $("#progress-text").html("");
                $(".am-progress-bar").css("width","0%");
		          },
              done: function (e, data) {
		         parent.layer.close(index);	 
                sendMessage({title: data.result.message, text: "", type: "success", showConfirmButton: true});
                setTimeout(function() {
                  $("#progress-area").addClass("am-hide");    
                },1500);        
		          },
              progressall: function (e, data) {
                var progress = parseInt(data.loaded / data.total * 100, 10);
                $(".am-progress-bar").css("width",progress + "%");
                $("#progress-text").html(progress + "%");
		          },
              error: function (jqXHR, textStatus, errorThrown) {
		         parent.layer.close(index);	
                // console.log(jqXHR);
                // console.log(textStatus);
                // console.log(errorThrown);
                $("#progress-area").removeClass("am-hide");
                $("#progress-text").addClass("am-text-danger");
                $("#progress-text").html("imageupload error！");
                $(".am-progress-bar").css("width","0%");
                setTimeout(function() {
                  $("#progress-area").addClass("am-hide");    
                },2000);
		          },
              fail: function (jqXHR, textStatus) {
	             parent.layer.close(index);     
                // console.log(jqXHR);
                // console.log(textStatus);
                $("#progress-area").removeClass("am-hide");
                $("#progress-text").addClass("am-text-danger");
                $("#progress-text").html("imageupload fail！");
                $(".am-progress-bar").css("width","0%");
                setTimeout(function() {
                  $("#progress-area").addClass("am-hide");    
                },2000);
		          }
		      });
            /*附件上传：end*/

		
			
		});
	</script>
	<%}%>